﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LGPeWJNM.BaseClasses;
using LGPeWJNM.DataAccessLayer;

namespace LGPeWJNM.BatchProcessBranchAndCut
{
    public partial class Mapa : Form
    {
        public Mapa(Cliente[][] Rotas, IdInstancia Inst)
        {
            InitializeComponent();

            this.Text = string.Format("{0}/{1}", Inst.Classe, Inst.Instancia);
            var series = Rotas
                .Select((rota, id) =>
                    {
                        var serie = new System.Windows.Forms.DataVisualization.Charting.Series();
                        serie.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
                        serie.Name = string.Format("Caminhão {0} Demanda {1}", id + 1, rota.Sum(s => s.Demanda));
                        //serie.BorderWidth = 1;
                        serie.Points.DataBindXY(rota.Select(no => no.Coordenada.X).ToList()
                            , rota.Select(no => no.Coordenada.Y).ToList());
                        return serie;
                    });
            foreach (var serie in series)
                this.cMapa.Series.Add(serie);

            var pontos = Rotas.SelectMany(rota => rota).Distinct().Cast<Cliente>().ToList();

            var seriePontos = new System.Windows.Forms.DataVisualization.Charting.Series();
            seriePontos.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Point;
            seriePontos.Name = "Nós (Clientes/Depósito)";
            seriePontos.BorderWidth = 3;
            seriePontos.Points.DataBindXY(pontos.Select(ponto => ponto.Coordenada.X).ToList(), pontos.Select(ponto => ponto.Coordenada.Y).ToList());
            foreach (var ponto in pontos)
                seriePontos.Points[pontos.IndexOf(ponto)].Label = ponto.Id.ToString();
            this.cMapa.Series.Add(seriePontos);
        }
    }
}
